When a function is initially called, the first thing it typically does in its prolog code is to save the contents of the hardware registers. The register contents at function call time represent the state of the calling function, and this state must be restored when the called function returns. Since the called function will most likely need to use the hardware registers for its own purposes, the contents of any registers (general purpose, floating point, etc.) that may be changed must first be saved in what is referred to as a register save area.
A called function may also need some working storage where it can place its automatic data, which is data with a scope limited to the duration of the called function. When the called function returns, its automatic data is no longer required.
Both of these storage requirements can be satisfied through the use of a dynamic storage area or Stack. The Stack can be comprised of several Stack Segments that are considered contiguous in storage from the application's perspective, although they may reside in real memory at discontinuous storage locations. The Stack consists of storage that is specific to a single thread of program execution. Typically, every function that has been called but not yet returned during the current program's execution is represented in the Stack by a Stack Frame.
Typically, the prolog code for a function that has just been called will save the calling function's registers and/or allocate storage for its Stack Frame before it does anything else. For example, function prolog code may save the calling function's registers into a register save area in a Stack Frame that was allocated by the calling function and is pointed to by a register. The Stack Frame size of the called function, which is known at compile time, is used to determine if the called function's Stack Frame will fit within the current Stack Segment. If it does not, a new Stack Segment is allocated. The code also saves the address of the calling function's Stack Frame into the new Stack Frame allocated by the called function. This saved address, known as a Stack Frame Backchain Pointer, can be used to find the calling function's Stack Frame. The process of traversing backwards through the Stack towards older calling functions is known as Stack Unwinding. The called function's epilog code restores the register containing the calling function's Stack Frame address, using the Stack Frame Backchain Pointer, before it returns control to the calling function.
Unfortunately, saving and restoring the Stack Frame Backchain Pointer in a called function's Stack Frame adds instruction cycles to the prolog and epilog code sections of every function that is called during the execution of the application. For programming languages built around an object-oriented paradigm (e.g., C++ and Java), there may be many function calls, some to functions having an actual “function body” (the executable instructions between the function prolog and epilog) that is small relative to the sizes of the prolog and epilog sections. In these cases, there can be a significant performance benefit by eliminating unnecessary instruction cycles (“call linkage overhead”) from the prolog and epilog code sections. Accordingly, for such function calls it is desirable to provide a method to unwind Stack Frames without the need for a Stack Frame Backchain Pointer in each Stack Frame.